#include <xscript/xscriptexecutor.h>
#include <xscript/xitemlist.h>
#include <astree/xabstractsyntaxtreereturn.h>

XAbstractSyntaxTreeReturn::XAbstractSyntaxTreeReturn(XTokenPtr inputToken):
    XAbstractSyntaxTree(inputToken) {
    setName(L"return");
}

bool XAbstractSyntaxTreeReturn::invoke(std::shared_ptr<XVariableTable> table) {
    auto value = std::make_shared<XItemList>();
    for (size_t i = 0; i < getChildCount(); i++) {
        auto child = getChildAt(i);
        if (!child->invoke(table))
            return false;
        value->addItem(child->getResult());
    }

    result = std::move(value);
    return true;
}
